
// create namespace
Ext.namespace('zr.dms');
// 定义目录树
zr.dms.FolderTree = function(config) {
	Ext.apply(this, config);
	zr.dms.FolderTree.superclass.constructor.call(this, {
				id : 'folderTree',
				autoScroll : true,
				// tree-specific configs:
				rootVisible : false,
				lines : false,
				singleExpand : false,
				rootVisible : true,
				border : false,
				useArrows : true,
				loader : new Ext.tree.TreeLoader({
							dataUrl : context + '/app/dms.do?method=treeNodes'
						}),
				root: new Ext.tree.AsyncTreeNode({
					text :'我的文档',
					id :'-1',
					expanded :true
				}),
				listeners : {
					'click' : {
						fn : function(node, e) {
							if (!node.isExpanded()) {
								node.expand();
							}
							
						},
						scope : this
					}
				}
			});

};

// 目录树继承treepanel
Ext.extend(zr.dms.FolderTree, Ext.tree.TreePanel, {
			title : '我的文档',
			region : 'north',
			split : true,
			height : 300,
			minSize : 150,
			autoScroll : true,
			/**
			 * 展开指定的树节点
			 */
			expandNode : function(id) {
				var node = this.getNodeById(id);
				var sm = this.getSelectionModel();
				node.expand(false, true, function(n) {
							sm.clearSelections();
							sm.select(n);
						});
			},
			
			/**
			 * 将指定路径的树节点展开 
			 */
		 	expandPath: function(path, attr, callback) {
				var sm = this.getSelectionModel();
				
				zr.dms.FolderTree.superclass.expandPath.call(this, 
						path, attr, function(bSuccess, oLastNode){
					if(bSuccess) {
						sm.clearSelections();
						sm.select(oLastNode);
					}
					if(callback) {
						callback.call(this, bSuccess, oLastNode);
					}
				});
			},

			/**
			 * 重现加载指定的树节点
			 */
			reloadNode : function(id, callback) {
				var node = this.getNodeById(id);
				if(node) {
					var sm = this.getSelectionModel();
					sm.clearSelections();
					//叶子节点没有reload方法，刷新其父节点
					if(node.leaf){ 
					var pNode = node.parentNode;
					pNode.reload();
					pNode.expand();
					node.expand();
					}else{
					node.reload(callback); 
					}
					
					
				}
			}

		});
